﻿#region << 文 件 说 明 >>
/*----------------------------------------------------------------
// 文件名称：IIocManager
// 创 建 人：YangCheng
// 创建时间：2022/5/24 18:40:43
// 文件版本：V1.0.0
// ===============================================================
// 功能描述：
//		
//
//----------------------------------------------------------------*/
#endregion

//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Reflection;
//using System.Text;
//using System.Threading.Tasks;

/*
 * 代码来源：
 * https://github.com/sunshine5516/ABP_SunFramework/tree/f20f6346063ac749c309d167192348c67cc5b2dd/src/AbpFramework/Dependency
 */

//namespace Vampirewal.Core.VContainer
//{
//    /// <summary>
//    /// IOC容器接口
//    /// </summary>
//    public interface IIocManager: IIocRegistrar, IIocResolver, IDisposable
//    {
//        /// <summary>
//        /// IWindsorContainer注入容器
//        /// </summary>
//        //IWindsorContainer IocContainer { get; }
//        /// <summary>
//        /// 类型是否已经注册
//        /// </summary>
//        /// <param name="type"></param>
//        /// <returns></returns>
//        new bool IsRegistered(Type type);
//        /// <summary>
//        /// 类型是否已经注册
//        /// </summary>
//        /// <typeparam name="T">Type to check</typeparam>
//        new bool IsRegistered<T>();
//    }

//    public interface IIocRegistrar
//    {
//        /// <summary>
//        /// 添加常规注册的依赖注册器。
//        /// </summary>
//        /// <param name="registrar">依赖注入</param>
//        void AddConventionalRegistrar(IConventionalDependencyRegistrar registrar);
//        void RegisterAssemblyByConvention(Assembly assembly);
//        /// <summary>
//        /// 注册程序集
//        /// </summary>
//        /// <param name="assembly">Assembly to register</param>
//        /// <param name="config">Additional configuration</param>
//        void RegisterAssemblyByConvention(Assembly assembly, ConventionalRegistrationConfig config);

//        void Register<T>(DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton)
//            where T : class;
//        void Register(Type type, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton);


//        /// <summary>
//        /// Registers a type with it's implementation.
//        /// </summary>
//        /// <typeparam name="TType">Registering type</typeparam>
//        /// <typeparam name="TImpl">The type that implements <see cref="TType"/></typeparam>
//        /// <param name="lifeStyle">Lifestyle of the objects of this type</param>
//        void Register<TType, TImpl>(DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton)
//            where TType : class
//            where TImpl : class, TType;

//        /// <summary>
//        /// Registers a type with it's implementation.
//        /// </summary>
//        /// <param name="type">Type of the class</param>
//        /// <param name="impl">The type that implements <paramref name="type"/></param>
//        /// <param name="lifeStyle">Lifestyle of the objects of this type</param>
//        void Register(Type type, Type impl, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton);

//        /// <summary>
//        /// Checks whether given type is registered before.
//        /// </summary>
//        /// <param name="type">Type to check</param>
//        bool IsRegistered(Type type);

//        /// <summary>
//        /// Checks whether given type is registered before.
//        /// </summary>
//        /// <typeparam name="TType">Type to check</typeparam>
//        bool IsRegistered<TType>();
//    }

//    public interface IIocResolver
//    {
//        /// <summary>
//        /// 从IOC容器获取对象。
//        /// Returning object must be Released (see <see cref="Release"/>) after usage.
//        /// </summary> 
//        /// <typeparam name="T">获取的对象的类型</typeparam>
//        /// <returns>对象实例</returns>
//        T Resolve<T>();
//        /// <summary>
//        /// 从IOC容器获取对象.
//        /// Returning object must be Released (see <see cref="Release"/>) after usage.
//        /// </summary> 
//        /// <typeparam name="T">要投射的物体的类型</typeparam>
//        /// <param name="type">要解析的对象的类型</param>
//        /// <returns>对象实例</returns>
//        T Resolve<T>(Type type);
//        /// <summary>
//        /// 从IOC容器获取对象
//        /// Returning object must be Released (see <see cref="Release"/>) after usage.
//        /// </summary> 
//        /// <typeparam name="T">要获取的对象的类型</typeparam>
//        /// <param name="argumentsAsAnonymousType">构造函数参数</param>
//        /// <returns>对象实例</returns>
//        T Resolve<T>(object argumentsAsAnonymousType);
//        /// <summary>
//        /// 从IOC容器获取对象
//        /// </summary>
//        /// <param name="type">要获取的对象的类型</param>
//        /// <returns>对象实例</returns>
//        object Resolve(Type type);
//        /// <summary>
//        /// 从IOC容器获取对象.
//        /// Returning object must be Released (see <see cref="Release"/>) after usage.
//        /// </summary> 
//        /// <param name="type">要获取的对象的类型</param>
//        /// <param name="argumentsAsAnonymousType">构造函数参数s</param>
//        /// <returns>对象实例</returns>
//        object Resolve(Type type, object argumentsAsAnonymousType);
//        /// <summary>
//        /// 获取给定类型的所有实现
//        /// </summary>
//        /// <typeparam name="T">要解析的对象的类型</typeparam>
//        /// <returns>对象实例</returns>
//        T[] ResolveAll<T>();
//        /// <summary>
//        /// 获取给定类型的所有实现.
//        /// Returning objects must be Released (see <see cref="Release"/>) after usage.
//        /// </summary> 
//        /// <typeparam name="T">要解析的对象的类型</typeparam>
//        /// <param name="argumentsAsAnonymousType">构造函数参数</param>
//        /// <returns>对象实例</returns>
//        T[] ResolveAll<T>(object argumentsAsAnonymousType);
//        /// <summary>
//        /// 获取给定类型的所有实现
//        /// Returning objects must be Released (see <see cref="Release"/>) after usage.
//        /// </summary> 
//        /// <param name="type">要解析的对象的类型</param>
//        /// <returns>对象实例</returns>
//        object[] ResolveAll(Type type);
//        /// <summary>
//        /// 获取给定类型的所有实现.
//        /// Returning objects must be Released (see <see cref="Release"/>) after usage.
//        /// </summary> 
//        /// <param name="type">要解析的对象的类型</param>
//        /// <param name="argumentsAsAnonymousType">构造函数名</param>
//        /// <returns>对象实例</returns>
//        object[] ResolveAll(Type type, object argumentsAsAnonymousType);
//        /// <summary>
//        /// 释放预先解析的对象。 请参阅解析方法。
//        /// </summary>
//        /// <param name="obj">要释放的对象d</param>
//        void Release(object obj);
//        /// <summary>
//        /// 检查给定类型是否在之前注册.
//        /// </summary>
//        /// <param name="type">检测类型</param>
//        bool IsRegistered(Type type);
//        /// <summary>
//        /// Checks whether given type is registered before.
//        /// </summary>
//        /// <typeparam name="T">Type to check</typeparam>
//        bool IsRegistered<T>();
//    }

//    public interface IConventionalDependencyRegistrar
//    {
//        /// <summary>
//        /// 注册程序集
//        /// </summary>
//        /// <param name="context"></param>
//        void RegisterAssembly(IConventionalRegistrationContext context);
//    }

//    public interface IConventionalRegistrationContext
//    {
//        /// <summary>
//        /// 要注册的程序集
//        /// </summary>
//        Assembly Assembly { get; }
//        IIocManager IocManager { get; }
//        /// <summary>
//        /// 注册的配置
//        /// </summary>
//        ConventionalRegistrationConfig Config { get; }
//    }

//    /// <summary>
//    ///  用来注册基本的依赖实现，比如<see cref ="ITransientDependency"/>
//    /// 和<see cref ="ISingletonDependency"/>。
//    /// </summary>
//    public class BasicConventionalRegistrar : IConventionalDependencyRegistrar
//    {
//        public void RegisterAssembly(IConventionalRegistrationContext context)
//        {

//            //注册拦截器  
//            //context.IocManager.IocContainer.Register(
//            //    Classes.FromThisAssembly()
//            //    .BasedOn<IInterceptor>()
//            //    .WithService.Self()
//            //    .LifestyleTransient());

//            //Transient
//            //context.IocManager.IocContainer.Register(
//            //    Classes.FromAssembly(context.Assembly)
//            //        .IncludeNonPublicTypes()
//            //        .BasedOn<ITransientDependency>()
//            //        .If(type => !type.GetTypeInfo().IsGenericTypeDefinition)
//            //        .WithService.Self()
//            //        .WithService.DefaultInterfaces()
//            //        .LifestyleTransient()
//            //    );
//            //context.IocManager.IocContainer.Register(
//            //    Classes.FromAssembly(context.Assembly)
//            //    .IncludeNonPublicTypes()
//            //    .BasedOn<ISingletonDependency>()
//            //    .If(type => !type.GetTypeInfo().IsGenericTypeDefinition)
//            //    .WithService.Self()
//            //    .WithService.DefaultInterfaces()
//            //    .LifestyleSingleton()
//            //    );
//            ////Windsor Interceptors
//            //context.IocManager.IocContainer.Register(
//            //  Classes.FromAssembly(context.Assembly)
//            //      .IncludeNonPublicTypes()
//            //      .BasedOn<IInterceptor>()
//            //      .If(type => !type.GetTypeInfo().IsGenericTypeDefinition)
//            //      .WithService.Self()
//            //      .LifestyleTransient()
//            //  );

//        }
//    }

//    /// <summary>
//    /// 类用于以传统方式注册类时传递配置
//    /// </summary>
//    public class ConventionalRegistrationConfig
//    {
//        /// <summary>
//        /// 是否注册所有的<see cref ="IInterceptor"/>实现。
//        /// 默认: true. 
//        /// </summary>
//        public bool InstallInstallers { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        public ConventionalRegistrationConfig()
//        {
//            InstallInstallers = true;
//        }
//    }

//    public enum DependencyLifeStyle
//    {
//        Singleton,

//        /// <summary>
//        /// Transient object. Created one object for every resolving.
//        /// </summary>
//        Transient
//    }

//    internal class DisposableDependencyObjectWrapper : DisposableDependencyObjectWrapper<object>, IDisposableDependencyObjectWrapper
//    {
//        public DisposableDependencyObjectWrapper(IIocResolver iocResolver, object obj)
//           : base(iocResolver, obj)
//        {

//        }
//    }
//    internal class DisposableDependencyObjectWrapper<T> : IDisposableDependencyObjectWrapper<T>
//    {
//        private readonly IIocResolver _iocResolver;
//        public T Object { get; private set; }
//        public DisposableDependencyObjectWrapper(IIocResolver iocResolver, T obj)
//        {
//            _iocResolver = iocResolver;
//            Object = obj;
//        }
//        public void Dispose()
//        {
//            _iocResolver.Release(Object);
//        }
//    }

//    /// <summary>
//    /// 该接口用于包装从IOC容器解析的对象
//    /// </summary>
//    public interface IDisposableDependencyObjectWrapper : IDisposableDependencyObjectWrapper<object>
//    {

//    }

//    /// <summary>
//    /// 该接口用于包装从IOC容器解析的对象
//    /// </summary>
//    /// <typeparam name="T"></typeparam>
//    public interface IDisposableDependencyObjectWrapper<out T> : IDisposable
//    {
//        /// <summary>
//        /// 解析对象
//        /// </summary>
//        T Object { get; }
//    }

//    /// <summary>
//    /// 此接口用于在单个语句中包装批处理解析的范围
//    /// </summary>
//    public interface IScopedIocResolver : IIocResolver, IDisposable { }

//    /// <summary>
//    /// 所有实现这个接口的类都被自动注册为依赖注入作为单例对象
//    /// </summary>
//    public interface ISingletonDependency
//    {
//    }

//    /// <summary>
//    /// 实现这个接口的所有类都会自动注册为依赖注入作为临时对象。
//    /// </summary>
//    public interface ITransientDependency
//    {
//    }
//}
